package com.waya.web;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.webkit.URLUtil;
import android.webkit.ValueCallback;

import com.waya.web.browser.ShowDialogActivity;
import com.waya.web.browser.WayeWebViewbActivity;
import com.waya.web.browser.common.util.AndroidUtils;
import com.waya.web.browser.common.util.ApkUtil;
import com.waya.web.browser.common.util.DownloadUtil;
import com.waya.web.browser.manager.WbWebManager;
import com.waye.wanba.utils.APPLog;

import java.io.File;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    String url = "http://172.18.104.11:8088/uploadServer/upload/apk/WeiYiKeJi/TouLanWang/com.udte.tlw-1-v1.0.1.true.apk";

    public void onBtnClick(View v) {
        switch (v.getId()) {
            case R.id.btn1:
                startActivity(new Intent(this, JsJavaActivity.class));
                break;
            case R.id.btn2:
                WbWebManager.getInstance(this).removeAllCookies(new ValueCallback<Boolean>() {
                    @Override
                    public void onReceiveValue(Boolean value) {
                        Log.d(TAG, "onReceiveValue: " + value.booleanValue());
                    }
                });
                break;
            case R.id.btn3:

                String path = AndroidUtils.getDownloadDir(url);
                final File file = new File(path);
                if (file.exists()) {
                    file.delete();
                }
                DownloadUtil.getInstance().download(url, file,
                        new DownloadUtil.AbsResponse() {
                            @Override
                            public void onResponse(String data) {
                                super.onResponse(data);
                                APPLog.printInfo("下载结果===》" + data);
                                ApkUtil.installApk(MainActivity.this, file.getAbsolutePath());
                            }

                            @Override
                            public void onError(String error) {
                                super.onError(error);
                                APPLog.printDebug(error);
                            }
                        });
                break;
            case R.id.btn4:
                APPLog.printDebug(AndroidUtils.getValue(MainActivity.this, "ip"));
            case R.id.btn5:
                ApkUtil.startApp(MainActivity.this, "com.udte.tlw", "com.udte.tlw.MainActivity", null, null, null, null);
                break;
            case R.id.btn6:
                Intent intent = new Intent("com.waya.web.activity");
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//                String s2 = "http://h5games.qcast.cn/happycastle_unicom/gamehall/index.html";
                String s2 = "file:///android_asset/error.html";
                intent.putExtra(WayeWebViewbActivity.KEY_URL, s2);
                startActivity(intent);
                break;
            case R.id.btn7:
                Intent intent2 = new Intent("com.waya.web.dialog");
                intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent2.putExtra(ShowDialogActivity.KEY_WIDTH, -1);
                intent2.putExtra(ShowDialogActivity.KEY_HEIGHT, -1);
                String s = "http://h5games.qcast.cn/happycastle_unicom/gamehall/index.html";
                intent2.putExtra(ShowDialogActivity.KEY_URL, s);
                startActivity(intent2);
                break;
            case R.id.btn8:
//                Intent intent3 = new Intent("com.waya.web.simple");
//                intent3.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//                startActivity(intent3);
                break;
            default:
                break;
        }
    }
}
